package com.sportswork.sportswork.controller.admin;

import com.sportswork.sportswork.core.entity.Info;
import com.sportswork.sportswork.core.entity.Ktinfo;
import com.sportswork.sportswork.core.service.dto.PageDTO;
import com.sportswork.sportswork.core.service.impl.InfoServiceImp;
import com.sportswork.sportswork.core.service.impl.KtinfoServiceImp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @author dengwei
 * @date 2020/2/3 12:11
 * @description
 */
@Slf4j
@Controller("KtinfoController")
public class KtinfoController {
    @Resource
    private KtinfoServiceImp ktinfoServiceImp;

    @RequestMapping("/admin/ktinfo/list")
    public String List(){
        return "/pages/view/admin/ktinfo/list";
    }

    @RequestMapping("/admin/ktinfo/getAllKtinfo")
    @ResponseBody
    public Object getAllKtinfo(String ktmc){
        return new  PageDTO<Ktinfo>().toPageDTO(ktinfoServiceImp.getAllKtinfos(ktmc));
    }

    @RequestMapping(value = "/admin/ktinfo/add", method = RequestMethod.POST)
    @ResponseBody
    public String add(Ktinfo ktinfo) {
        ktinfoServiceImp.addKtinfo(ktinfo);
        return "success";
    }

    @RequestMapping(value = "/admin/ktinfo/edit", method = RequestMethod.POST)
    @ResponseBody
    public String edit(Ktinfo ktinfo) {
        ktinfoServiceImp.setKtinfo(ktinfo);
        return "success";
    }

    @RequestMapping(value = "/admin/ktinfo/delete", method = RequestMethod.POST)
    @ResponseBody
    public String delete(@RequestParam String id) {
        ktinfoServiceImp.deleteKtinfo(id);
        return "true";
    }

    @RequestMapping(value = "/admin/ktinfo/deletes", method = RequestMethod.POST)
    @ResponseBody
    public String deletes(@RequestParam String ids) {
        ktinfoServiceImp.deleteKtinfos(ids );
        return "true";
    }
}
